<template>
	<el-select v-model="selectedId" filterable clearable :disabled="disabled" @change="handleChange">
        <el-option
            v-for="(item,index) in models"
            :key="index"
            :label="getLabel(item)"
            :value="item.jx"
		>
        </el-option>
	</el-select>
</template>
<script lang="ts">
import { defineComponent,onMounted,reactive, ref, toRefs} from 'vue'
import request from '/@/utils/request'

export default defineComponent({
    name: 'vpAircraftTypeSelect',
    emits: ['selected'],
    props: {
        selectedId: String,
        NA : Boolean,
        auth : {
            type: Boolean,
            default : false
        },
        fjzch: {
            type: Boolean,
            default: true,
        },
        fjxlh: {
            type: Boolean,
            default: false,
        },
        jx: {
            type: Boolean,
            default: false,
        },
        disabled: {
            type: Boolean,
            default: false,
        }
    },
    setup(props, context) {
        const state = reactive({
            loading: false,
            models:[],
        })
        const loadData = ()=>{
            state.loading = true
			request.get('/basicData/acmodel/list',{
                params:{
                    zt: 10,
                    allData: !props.auth,
                }
            }).then(res => {
                state.models = res?.data || []
            }).finally(()=>{
				state.loading = false
			})
        }
       
        onMounted(()=>{
            loadData();
        })
        const selectRef = ref();
        const handleChange = (data:any)=>{
            let obj={}
			state.models.forEach(item=>{
				if (data == item.jx){
                    obj = item;
				}
			})
            context.emit("selected", obj);
        }

        const getLabel = (item: any) => {
				return item.jx;
			}
        return {
            ...toRefs(state),
            ...toRefs(props),
            handleChange,
            selectRef,
            getLabel,
        }
    }
})
</script>
